<template>
	<view>
		<view v-for="(item,index) in list" :key="index" class="u-border-bottom">
			<Diary :border-bottom="false" :showMore="true" :user-info="item.compassNormalUser" :type-click="false"
				@like-change="res => likeChange(index, res)" @delete="deleteCallback(index)" :info-data="item" />
		</view>
		<loadMore :status="status" />
		<!-- 发布按钮开始 -->
		<view class="fabu" @click="toFabu">
			<img src="https://app.zbzedu.com/static/WaChat/icon/forum/publish.png" mode="" />
		</view>
		<!-- 发布按钮结束 -->
	</view>
</template>

<script>
	import Diary from '../../pages/forum/components/Diary'
	import {
		request
	} from '../../util/api'
	import loadMore from '../../components/loadMore'
	import {
		getCurrentFullPath
	} from "../../util/util";
	export default {
		name: 'diaryList',
		components: {
			Diary,
			loadMore
		},

		onLoad(option) {
			const name=decodeURIComponent(option.type)
			this.diaryType=name
			uni.setNavigationBarTitle({
				title: decodeURIComponent(this.diaryType)
			});
			if (option.id) {
				this.userId = option.id
			}
			if (option.type) {
				this.diaryType = name
				
			}
			if (option.title) {
				
			}
		},

		data() {
			return {
				userId: '',
				list: [],
				status: 'loading',
				pageNum: 1,
				diaryType: ''
			}
		},

		computed: {
			isCurrentUser() {
				if (this.userId && this.userId != uni.getStorageSync(process.env.NODE_ENV + 'zbz_user').userId) {
					return false
				}
				return true
			}
		},

		mounted() {
			this.status = 'loading'
			this.pageNum = 1
			this.list = []
			this.getList()
		},

		methods: {
			// 转发功能
			onShareAppMessage(res) {
				return {
					path: getCurrentFullPath()
				}
			},
			toFabu() {
				uni.navigateTo({
					url:"/package/discussion/publish?talkType="+decodeURIComponent(this.diaryType)
				})
			},
			
			deleteCallback(index) {
				this.list.splice(index, 1)
			},

			likeChange(index, data) {
				const {
					likeFlag,
					likeNum
				} = data
				this.$set(this.list[index], 'likeFlag', likeFlag)
				this.$set(this.list[index], 'likeNum', likeNum)
			},

			getList() {
				const uId = this.userId ? this.userId : uni.getStorageSync(process.env.NODE_ENV + 'zbz_user').userId
				if (this.diaryType) {
					request({
						url: '/system/CompassDiary/list',
						data: {
							pageNum: this.pageNum,
							pageSize: 10,
							diaryType: decodeURIComponent(this.diaryType)
						},
						not_loading: true
					}).then(res => {
						this.list = this.list.concat(res.rows)
						this.pageNum++
						if (this.list.length >= res.total) {
							this.status = 'finished'
						} else {
							this.status = ''
						}
					})
				} else {
					request({
						url: '/system/CompassDiary/getMyList/' + uId,
						data: {
							pageNum: this.pageNum,
							pageSize: 10
						},
						not_loading: true
					}).then(res => {
						this.list = this.list.concat(res.rows)
						this.pageNum++
						if (this.list.length >= res.total) {
							this.status = 'finished'
						} else {
							this.status = ''
						}
					})
				}
			}
		},

		onReachBottom() {
			if (!this.status) {
				this.status = 'loading'
				this.getList()
			}
		}
	}
</script>

<style scoped lang="scss">
.fabu {
		position: fixed;
		right: 28rpx;
		bottom: 130rpx;
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		height: 120rpx;
		z-index: 10;

		image {
			width: 100%;
			height: 100%;
		}

	}
</style>
